﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

using KSOAdmin.Models.Core;
using KSOAdmin.Models.MapperModels.Enums;
using KSOAdmin.Models.MapperModels.Page;

using Microsoft.AspNetCore.Http;

namespace KSOAdmin.IServices
{
    public interface IBasicServices<TModel> where TModel : class, new()
    {

        #region 查询
        public TModel FindFirst(Expression<Func<TModel, bool>> expression );
        /// <summary>
        /// 异步获取第一个
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<TModel> FindFirstAsync(Expression<Func<TModel, bool>> expression );

        public Task<List<TModel>> FindListAsync(Expression<Func<TModel, bool>> expression = null, Expression<Func<TModel, Dictionary<object, QueryOrderBy>>> orderBy = null, bool isTracking = true);
        public IQueryable<TModel> FindAsIQueryable(Expression<Func<TModel, bool>> predicate = null, Expression<Func<TModel, Dictionary<object, QueryOrderBy>>> orderBy = null, bool isTracking = true);
        /// <summary>
        /// 自定义泛型
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="predicate"></param>
        /// <param name="isTracking"></param>
        /// <returns></returns>
        public IQueryable<T> FindOtherIQueryable<T>(Expression<Func<T, bool>> predicate = null, Expression<Func<T, Dictionary<object, QueryOrderBy>>> orderBy = null, bool isTracking = true) where T : class;
        public Task<List<T>> FindOtherListAsync<T>(Expression<Func<T, bool>> predicate = null, bool isTracking = true) where T : class;

        #endregion

        #region 分页
        public IQueryable<T> IQueryablePage<T>(out int rowcount, Expression<Func<T, bool>> predicate, Expression<Func<T, Dictionary<object, QueryOrderBy>>> orderBy = null, int pageIndex = 1, int pageSize = 20) where T : class;

        public IQueryable<TModel> IQueryablePage(out int rowcount, Expression<Func<TModel, bool>> predicate, Expression<Func<TModel, Dictionary<object, QueryOrderBy>>> orderBy = null, int pageIndex = 1, int pageSize = 20);
        public Task<PageListModel<TModel>> PageListAsync(Expression<Func<TModel, bool>> predicate, Expression<Func<TModel, Dictionary<object, QueryOrderBy>>> orderBy = null, int pageIndex = 1, int pageSize = 20);
        Task<PageListModel<TModel>> PageListAsync(IQueryable<TModel> queryable, Expression<Func<TModel, Dictionary<object, QueryOrderBy>>> orderBy = null, int pageIndex = 1, int pageSize = 20);
        Task<PageListModel<T>> PageOtherListAsync<T>(IQueryable<TModel> queryable, Expression<Func<T, Dictionary<object, QueryOrderBy>>> orderBy = null, int pageIndex = 1, int pageSize = 20) where T : class;
        #endregion

        #region 增删改
        Task<ResponseModel<TModel>> Upload(List<TModel> files);

        Task<ResponseModel<TModel>> Upload(TModel TModel);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity">保存的实体</param>
        /// <param name="validationEntity">是否对实体进行校验</param>
        /// <returns></returns>
        Task<ResponseModel<TModel>> AddEntity(TModel entity, bool validationEntity = true);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity">保存的实体</param>
        /// <param name="validationEntity">是否对实体进行校验</param>
        /// <returns></returns>
        Task<ResponseModel<T>> AddEntity<T>(T entity, bool validationEntity = true) where T : class;

        /// <summary>
        /// 批量增加
        /// </summary>
        /// <param name="list">保存的明细</param>
        /// <param name="validationEntity">是否对实体进行校验</param>
        /// <returns></returns>
        Task<ResponseModel<TModel>> Add(List<TModel> list = null, bool validationEntity = true);

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="keys">删除的主键</param>
        /// <param name="delList">是否删除对应明细(默认会删除明细)</param>
        /// <returns></returns>
        Task<ResponseModel<TModel>> Del(object[] keys, bool delList = true);
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="keys">删除的主键</param>
        /// <param name="delList">是否删除对应明细(默认会删除明细)</param>
        /// <returns></returns>
        Task<ResponseModel<TModel>> Del(TModel TModel, bool delList = true);
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="keys">删除的主键</param>
        /// <param name="delList">是否删除对应明细(默认会删除明细)</param>
        /// <returns></returns>
        Task<ResponseModel<TModel>> Del(List<TModel> list, bool delList = true);
        #endregion

        #region 上传下载
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <returns></returns>
        Task<ResponseModel > DownLoadTemplate();
        /// <summary>
        /// 导入
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        Task<ResponseModel > Import(List<IFormFile> files);
        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="pageData"></param>
        /// <returns></returns>
        Task<ResponseModel > Export(PageDataOptions pageData); 
        #endregion

    }
}
